#ifndef __KERNELS_H__
#define __KERNELS_H__

const char* srcKernel =
"__kernel void Mult_CalcColIndex(const int n,                      \n"\
"                                __global float* valueA,           \n"\
"								 __global int* rowA,               \n"\
"								 __global int* colIndexA,          \n"\
"                                __global float* valueB,           \n"\
"								 __global int* rowB,               \n"\
"								 __global int* colIndexB,          \n"\
"								 __global int* colIndexC)          \n"\
"{                                                                 \n"\
"   int j = get_global_id(0) ;								       \n"\
"	if (j >= n) return;	                 			               \n"\

"   int ks, ls, kf, lf;											   \n"\
"   int countElem = 0;                                             \n"\
"	for (int i=0; i<n; i++)										   \n"\
"   {                                                              \n"\
"	   ks = colIndexA[i];										   \n"\
"	   kf = colIndexA[i+1];										   \n"\
"	   ls = colIndexB[j];										   \n"\
"	   lf = colIndexB[j+1];										   \n"\

"      bool isFound = false;                                       \n"\
"	   while ((ks < kf) && (ls < lf))							   \n"\
"	   {														   \n"\
"		   if (rowA[ks] < rowB[ls]) ks++;						   \n"\
"		   else													   \n"\
"			  if (rowA[ks] > rowB[ls]) ls++;					   \n"\
"			  else												   \n"\
"			  {													   \n"\
"                isFound = true;                                   \n"\
"                break;                                            \n"\
"			  }													   \n"\
"	   }                                                           \n"\
"      if (isFound) countElem++;                                   \n"\
"	}                                                              \n"\
"   colIndexC[j] = countElem;                                      \n"\
"}                                                                 \n"\

"__kernel void Mult_CalcValue(const int n,                         \n"\
"                                __global float* valueA,           \n"\
"								 __global int* rowA,               \n"\
"								 __global int* colIndexA,          \n"\
"                                __global float* valueB,           \n"\
"								 __global int* rowB,               \n"\
"								 __global int* colIndexB,          \n"\
"                                __global float* valueC,           \n"\
"                                __global int* rowC,               \n"\
"								 __global int* colIndexC)          \n"\
"{                                                                 \n"\
"   int j = get_global_id(0) ;								       \n"\
"	if (j >= n) return;	                 			               \n"\

"   int ks, ls, kf, lf;											   \n"\
"   int idxCurElem = colIndexC[j];                                 \n"\
"	for (int i=0; i<n; i++)										   \n"\
"   {                                                              \n"\
"	   ks = colIndexA[i];										   \n"\
"	   kf = colIndexA[i+1];										   \n"\
"	   ls = colIndexB[j];										   \n"\
"	   lf = colIndexB[j+1];										   \n"\

"      bool isFound = false;                                       \n"\
"      float sum = 0;                                              \n"\
"	   while ((ks < kf) && (ls < lf))							   \n"\
"	   {														   \n"\
"		   if (rowA[ks] < rowB[ls]) ks++;						   \n"\
"		   else													   \n"\
"			  if (rowA[ks] > rowB[ls]) ls++;					   \n"\
"			  else												   \n"\
"			  {													   \n"\
"                isFound = true;                                   \n"\
"                sum += valueA[ks] * valueB[ls];                   \n"\
"                ks++;                                             \n"\
"                ls++;                                             \n"\
"			  }													   \n"\
"	   }                                                           \n"\
"      if (isFound)                                                \n"\
"      {                                                           \n"\
"          valueC[idxCurElem] = sum;                               \n"\
"          rowC[idxCurElem] = i;                                   \n"\
"		   idxCurElem++;                                           \n"\
"      }                                                           \n"\
"	}                                                              \n"\
"}";

#endif
